package com.antler.smt.portal.controller;

import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.portal.annotation.OperateCut;
import com.antler.smt.request.admin.GetSupplierListReq;
import com.antler.smt.request.portal.SendReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.portal.IdentifyingCodeService;
import com.antler.smt.service.portal.SupplierService;
import com.antler.smt.utils.LogUtil;
import com.antler.smt.validate.DataValidator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 服务商入驻Controller
 *
 * @author zhangyi
 * @date 2018/4/2 17:37
 */
@RestController
@RequestMapping("/supplierSettled")
@Api(description = "服务商入驻接口")
@Slf4j
public class SupplierSettledController extends BaseController {
    @Resource
    private SupplierService supplierService;

    @Resource
    private IdentifyingCodeService identifyingCodeService;

    /**
     *  更新服务商入驻信息
     *
     * @param request
     * @param code 验证码信息
     * @return
     */
    @PostMapping("/settled/{code}")
    @ApiOperation(value = "更新服务商入驻信息", httpMethod = "POST")
    @OperateCut(operationContent = "服务商入驻")
    public Result<ResultCodeEnum> settled(@RequestBody GetSupplierListReq request,@PathVariable String code){
        DataValidator.isNull(request,"服务商实体不为空！");
        DataValidator.isBlank(request.getCompanyName(),"公司名称不能为空！");
        DataValidator.isBlank(request.getCreditCode(),"统一信用社码，不能为空！");
        DataValidator.isBlank(request.getDetailAddress(),"公司地址不能为空！");
        DataValidator.isBlank(request.getLegalPerson(),"法人不能为空！");
        DataValidator.isBlank(String.valueOf(request.getFoundTime()),"成立时间不能为空！");
        DataValidator.isBlank(request.getPublicAccount(),"对公账户不能为空！");
        DataValidator.isBlank(String.valueOf(request.getBusinessLicenseAttachmentId()),"营业执照不能为空");
        DataValidator.isBlank(String.valueOf(request.getBankPermitAttachmentId()),"银行执照不能为空！");
        DataValidator.isBlank(request.getProductInfo(),"生产线信息不能为空！");
        DataValidator.isBlank(String.valueOf(request.getCapacity()),"产能不能为空！");
        DataValidator.isBlank(request.getClassInfo(),"班组信息不能为空！");
        DataValidator.isBlank(request.getProductAdvantage(),"优势所长不能为空");
        DataValidator.isBlank(request.getResonseCycle(),"响应周期不能为空！");
        DataValidator.isBlank(request.getFinishCycle(),"交期不能为空！");
        DataValidator.isBlank(request.getQualityControl(),"品控不能为空！");
        DataValidator.isBlank(request.getTechnology(),"主要工艺不能为空！");
        DataValidator.isBlank(request.getLinkEmail(),"联系邮箱不能为空！");
        DataValidator.isBlank(request.getLinkMan(),"联系人不能为空！");
        DataValidator.isBlank(request.getLinkPhone(),"联系电话不能为空！");
        DataValidator.isBlank(code,"验证码必填！");

        Result result = null;
            result = supplierService.updateSupplierSettled(request,currentMember.getId(),code);
        return result;
    }

    /**
     *  服务商验证码发送验证
     *
     * @param receiver 接收者邮箱
     * @return
     */
    @PostMapping("/identifyingCode")
    @ApiOperation(value = "服务商验证码发送验证", httpMethod = "POST")
    public Result<ResultCodeEnum> identifyingCode(@RequestBody SendReq receiver){

        DataValidator.isNull(receiver,"接受实体不为空！");

        Result result = null;
            result = identifyingCodeService.sendCode(String.valueOf(currentMember.getId()),receiver);
        return result;
    }

    /**
     * 获取完成订单数量
     *
     * @return
     */
    @PostMapping("/excellentOrderCount")
    @ApiOperation(value = "获取完成订单数量", httpMethod = "POST")
    public Result<Integer> excellentOrderCount(){
        Result result = null;
            result = supplierService.excellentConunt(currentMember.getId());
        return result;
    }

    /**
     *  优质服务商申请
     *
     * @return
     */
    @PostMapping("/excellentApply")
    @ApiOperation(value = "优质服务商申请", httpMethod = "POST")
    @OperateCut(operationContent = "优质服务商申请")
    public Result<ResultCodeEnum> excellentApply(){
        Result result = null;
            result = supplierService.excellent(currentMember.getId());
        return result;
    }

    /**
     *  返回服务商入驻实体
     *
     * @return
     */
    @GetMapping("/supplierSettedInfo")
    @ApiOperation(value = "返回服务商入驻实体", httpMethod = "GET")
    public Result supplierSettedInfo(){
        Result result = null;
            result = supplierService.getSupplierSettedInfo(currentMember.getId());
        return result;
    }

}
